package edu.imac.angryfood.shapes;

import org.jbox2d.common.Vec2;

/**
 * A shape implementation defining a rectangle for collision 
 * 
 */
public class Rectangle extends PolygonBasedShape {
	/** The width of the rectangle */
	private float width;
	/** The height of the rectangle */
	private float height;
	
	/**
	 * Constructor
	 * @param width
	 * @param height
	 */
	public Rectangle(float width, float height) {
		this(width, height, DEFAULT_DENSITY, DEFAULT_RESTIUTION, DEFAULT_FRICTION);
	}
	
	/**
	 * Constructor
	 * @param width
	 * @param height
	 * @param density
	 */
	public Rectangle(float width, float height, float density) {
		this(width, height, density, DEFAULT_RESTIUTION, DEFAULT_FRICTION);
	}
	
	/**
	 * Constructor
	 * @param width
	 * @param height
	 * @param density
	 * @param resitution
	 */
	public Rectangle(float width, float height, float density, float resitution) {
		this(width, height, density, resitution, DEFAULT_FRICTION);
	}
	
	/**
	 * Constructor
	 * @param width
	 * @param height
	 * @param density
	 * @param restitution
	 * @param friction
	 */
	public Rectangle(float width, float height, float density, float restitution, float friction) {
		getDef().setAsBox(width / 2, height / 2);
		getDef().density = density;
		getDef().restitution = restitution;
		getDef().friction = friction;
		
		this.width = width;
		this.height = height;
		
		slickShape = new org.newdawn.slick.geom.Rectangle( (int) -(width/2),(int) -(height/2),width+1, height+1);
	}
	
	/**
	 * get the width
	 * @return width
	 */
	public float getWidth() {
		return width;
	}
	
	/**
	 * get the height
	 * @return height
	 */
	public float getHeight() {
		return height;
	}
	
	/**
	 * apply an offset
	 * @param x
	 * @param y
	 * @param angle
	 */
	@Override
	protected void applyOffset(float x, float y, float angle) {
		getDef().setAsBox(width/2, height/2, new Vec2(x,y), angle);
	}

}
